package com.lemon.blog.web.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.lemon.common.core.annotation.Excel;
import com.lemon.common.core.base.BaseEntity;
import com.lemon.common.core.serializer.JsonLongDeserializer;
import com.lemon.common.core.serializer.JsonLongSerializer;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * 包名称：com.lemon.system.domain
 * 类名称：BiUser
 * 类描述：普通用户表
 * 创建人：@author huangpeng
 * 创建时间：2023年01月07日 11:06
 */
public class BiUser extends BaseEntity implements Comparable<BiUser> {

    private static final long serialVersionUID = 1L;

    /** 用户id */
    @JsonSerialize(using = JsonLongSerializer.class)
    @JsonDeserialize(using = JsonLongDeserializer.class)
    private Long id;

    /** 登录名 */
    @Excel(name = "登录名")
    private String userCode;

    /** 用户名 */
    @Excel(name = "用户名")
    private String userName;

    /** 密码 */
    private String password;

    /** 性别 */
    @Excel(name = "性别", dictType = "sys_user_sex")
    private Long gender;

    /** 头像 */
    @Excel(name = "头像")
    private String avatar;

    /** 昵称 */
    @Excel(name = "昵称")
    private String nickName;

    /** 生日 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "生日", width = 30, dateFormat = "yyyy-MM-dd")
    private Date birthday;

    /** 邮箱 */
    @Excel(name = "邮箱")
    private String email;

    /** 电话 */
    @Excel(name = "电话")
    private String phone;

    /** QQ */
    @Excel(name = "QQ")
    private String qqNumber;

    /** 微信号 */
    @Excel(name = "微信号")
    private String weChat;

    /** 介绍 */
    @Excel(name = "介绍")
    private String summary;

    /** 签名 */
    @Excel(name = "签名")
    private String signature;

    /** 排序 */
    private Long orderNo;

    /** 用户类型 */
    @Excel(name = "用户类型", dictType = "sys_user_type")
    private String userType;

    /** 邮箱验证码 */
    private String validCode;

    /** 评论状态 */
    @Excel(name = "评论状态", dictType = "sys_normal_disable")
    private String commentStatus;

    /** ip来源 */
    private String ipSource;

    /** 浏览器 */
    private String browser;

    /** 操作系统 */
    private String oprationSystem;

    /** 邮件通知状态  */
    @Excel(name = "邮件通知状态 ", dictType = "sys_normal_disable")
    private String startEmailNotification;

    /** 是否通过加载校验【0 未通过，1 已通过】 */
    private String loadingValid;

    /** 资料来源 */
    @Excel(name = "资料来源", dictType = "sys_user_origin")
    private String dataOrigin;

    /** 资料来源平台的当前用户唯一uid */
    private String originUid;

    /** 职业 */
    @Excel(name = "职业")
    private String occupation;

    /** 启用状态 */
    @Excel(name = "启用状态", dictType = "sys_normal_disable")
    private String status;

    /** 密码错误次数 */
    @Excel(name = "密码错误次数")
    private Long loginErrorCount;

    /** 登录次数 */
    @Excel(name = "登录次数")
    private Long loginCount;

    /** 最后登录时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date lastLoginTime;

    /** 最后登录IP */
    @Excel(name = "最后登录IP")
    private String lastLoginIp;

    /** 密码到期时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "密码到期时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date expireTime;
    
    /**
     * 新密码
     */
    private String newPassword;

    /**
     * 背景图片
     */
    private String backUrl;
    
    /**
     * 用户统计信息-前端展示用
     */
    private Map<String, Object> userStatsMap;

    /**
     * 用户id-前端查询用
     */
    @JsonSerialize(using = JsonLongSerializer.class)
    @JsonDeserialize(using = JsonLongDeserializer.class)
    private Long userId;

    /**
     * 关注的用户id-前端查询用
     */
    @JsonSerialize(using = JsonLongSerializer.class)
    @JsonDeserialize(using = JsonLongDeserializer.class)
    private Long followUserId;

    /**
     * 前端模糊查询参数
     */
    private String keyWord;

    public void setId(Long id)
    {
        this.id = id;
    }

    public Long getId()
    {
        return id;
    }
    public void setUserCode(String userCode)
    {
        this.userCode = userCode;
    }

    public String getUserCode()
    {
        return userCode;
    }
    public void setUserName(String userName)
    {
        this.userName = userName;
    }

    public String getUserName()
    {
        return userName;
    }
    public void setPassword(String password)
    {
        this.password = password;
    }

    public String getPassword()
    {
        return password;
    }
    public void setGender(Long gender)
    {
        this.gender = gender;
    }

    public Long getGender()
    {
        return gender;
    }
    public void setAvatar(String avatar)
    {
        this.avatar = avatar;
    }

    public String getAvatar()
    {
        return avatar;
    }
    public void setNickName(String nickName)
    {
        this.nickName = nickName;
    }

    public String getNickName()
    {
        return nickName;
    }
    public void setBirthday(Date birthday)
    {
        this.birthday = birthday;
    }

    public Date getBirthday()
    {
        return birthday;
    }
    public void setEmail(String email)
    {
        this.email = email;
    }

    public String getEmail()
    {
        return email;
    }
    public void setPhone(String phone)
    {
        this.phone = phone;
    }

    public String getPhone()
    {
        return phone;
    }
    public void setQqNumber(String qqNumber)
    {
        this.qqNumber = qqNumber;
    }

    public String getQqNumber()
    {
        return qqNumber;
    }
    public void setWeChat(String weChat)
    {
        this.weChat = weChat;
    }

    public String getWeChat()
    {
        return weChat;
    }
    public void setSummary(String summary)
    {
        this.summary = summary;
    }

    public String getSummary()
    {
        return summary;
    }
    public void setSignature(String signature)
    {
        this.signature = signature;
    }

    public String getSignature()
    {
        return signature;
    }
    public void setOrderNo(Long orderNo)
    {
        this.orderNo = orderNo;
    }

    public Long getOrderNo()
    {
        return orderNo;
    }
    public void setLoginErrorCount(Long loginErrorCount)
    {
        this.loginErrorCount = loginErrorCount;
    }

    public Long getLoginErrorCount()
    {
        return loginErrorCount;
    }
    public void setLoginCount(Long loginCount)
    {
        this.loginCount = loginCount;
    }

    public Long getLoginCount()
    {
        return loginCount;
    }
    public void setLastLoginTime(Date lastLoginTime)
    {
        this.lastLoginTime = lastLoginTime;
    }

    public Date getLastLoginTime()
    {
        return lastLoginTime;
    }
    public void setLastLoginIp(String lastLoginIp)
    {
        this.lastLoginIp = lastLoginIp;
    }

    public String getLastLoginIp()
    {
        return lastLoginIp;
    }
    public void setExpireTime(Date expireTime)
    {
        this.expireTime = expireTime;
    }

    public Date getExpireTime()
    {
        return expireTime;
    }
    public void setUserType(String userType)
    {
        this.userType = userType;
    }

    public String getUserType()
    {
        return userType;
    }
    public void setValidCode(String validCode)
    {
        this.validCode = validCode;
    }

    public String getValidCode()
    {
        return validCode;
    }
    public void setCommentStatus(String commentStatus)
    {
        this.commentStatus = commentStatus;
    }

    public String getCommentStatus()
    {
        return commentStatus;
    }
    public void setIpSource(String ipSource)
    {
        this.ipSource = ipSource;
    }

    public String getIpSource()
    {
        return ipSource;
    }
    public void setBrowser(String browser)
    {
        this.browser = browser;
    }

    public String getBrowser()
    {
        return browser;
    }
    public void setOprationSystem(String oprationSystem)
    {
        this.oprationSystem = oprationSystem;
    }

    public String getOprationSystem()
    {
        return oprationSystem;
    }
    public void setStartEmailNotification(String startEmailNotification)
    {
        this.startEmailNotification = startEmailNotification;
    }

    public String getStartEmailNotification()
    {
        return startEmailNotification;
    }
    public void setLoadingValid(String loadingValid)
    {
        this.loadingValid = loadingValid;
    }

    public String getLoadingValid()
    {
        return loadingValid;
    }
    public void setDataOrigin(String dataOrigin)
    {
        this.dataOrigin = dataOrigin;
    }

    public String getDataOrigin()
    {
        return dataOrigin;
    }
    public void setOriginUid(String originUid)
    {
        this.originUid = originUid;
    }

    public String getOriginUid()
    {
        return originUid;
    }
    public void setOccupation(String occupation)
    {
        this.occupation = occupation;
    }

    public String getOccupation()
    {
        return occupation;
    }
    public void setStatus(String status)
    {
        this.status = status;
    }

    public String getStatus()
    {
        return status;
    }

    public String getNewPassword() {
        return newPassword;
    }

    public void setNewPassword(String newPassword) {
        this.newPassword = newPassword;
    }

    public String getBackUrl() {
        return backUrl;
    }

    public void setBackUrl(String backUrl) {
        this.backUrl = backUrl;
    }

    public Map<String, Object> getUserStatsMap() {
        return userStatsMap;
    }

    public void setUserStatsMap(Map<String, Object> userStatsMap) {
        this.userStatsMap = userStatsMap;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Long getFollowUserId() {
        return followUserId;
    }

    public void setFollowUserId(Long followUserId) {
        this.followUserId = followUserId;
    }

    public String getKeyWord() {
        return keyWord;
    }

    public void setKeyWord(String keyWord) {
        this.keyWord = keyWord;
    }

    public BiUser() {
    }

    public BiUser(Long userId, Long followUserId) {
        this.userId = userId;
        this.followUserId = followUserId;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("id", getId())
                .append("userCode", getUserCode())
                .append("userName", getUserName())
                .append("password", getPassword())
                .append("gender", getGender())
                .append("avatar", getAvatar())
                .append("nickName", getNickName())
                .append("birthday", getBirthday())
                .append("email", getEmail())
                .append("phone", getPhone())
                .append("qqNumber", getQqNumber())
                .append("weChat", getWeChat())
                .append("summary", getSummary())
                .append("signature", getSignature())
                .append("orderNo", getOrderNo())
                .append("loginErrorCount", getLoginErrorCount())
                .append("loginCount", getLoginCount())
                .append("lastLoginTime", getLastLoginTime())
                .append("lastLoginIp", getLastLoginIp())
                .append("expireTime", getExpireTime())
                .append("userType", getUserType())
                .append("validCode", getValidCode())
                .append("commentStatus", getCommentStatus())
                .append("ipSource", getIpSource())
                .append("browser", getBrowser())
                .append("oprationSystem", getOprationSystem())
                .append("startEmailNotification", getStartEmailNotification())
                .append("loadingValid", getLoadingValid())
                .append("dataOrigin", getDataOrigin())
                .append("originUid", getOriginUid())
                .append("occupation", getOccupation())
                .append("status", getStatus())
                .append("remark", getRemark())
                .append("createTime", getCreateTime())
                .append("createBy", getCreateBy())
                .append("updateTime", getUpdateTime())
                .append("updateBy", getUpdateBy())
                .append("delFlag", getDelFlag())
                .append("backUrl", getBackUrl())
                .toString();
    }


    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        BiUser other = (BiUser) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getUserCode() == null ? other.getUserCode() == null : this.getUserCode().equals(other.getUserCode()))
            && (this.getUserName() == null ? other.getUserName() == null : this.getUserName().equals(other.getUserName()))
            && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()))
            && (this.getGender() == null ? other.getGender() == null : this.getGender().equals(other.getGender()))
            && (this.getAvatar() == null ? other.getAvatar() == null : this.getAvatar().equals(other.getAvatar()))
            && (this.getNickName() == null ? other.getNickName() == null : this.getNickName().equals(other.getNickName()))
            && (this.getBirthday() == null ? other.getBirthday() == null : this.getBirthday().equals(other.getBirthday()))
            && (this.getEmail() == null ? other.getEmail() == null : this.getEmail().equals(other.getEmail()))
            && (this.getPhone() == null ? other.getPhone() == null : this.getPhone().equals(other.getPhone()))
            && (this.getQqNumber() == null ? other.getQqNumber() == null : this.getQqNumber().equals(other.getQqNumber()))
            && (this.getWeChat() == null ? other.getWeChat() == null : this.getWeChat().equals(other.getWeChat()))
            && (this.getSummary() == null ? other.getSummary() == null : this.getSummary().equals(other.getSummary()))
            && (this.getSignature() == null ? other.getSignature() == null : this.getSignature().equals(other.getSignature()))
            && (this.getOrderNo() == null ? other.getOrderNo() == null : this.getOrderNo().equals(other.getOrderNo()))
            && (this.getLoginErrorCount() == null ? other.getLoginErrorCount() == null : this.getLoginErrorCount().equals(other.getLoginErrorCount()))
            && (this.getLoginCount() == null ? other.getLoginCount() == null : this.getLoginCount().equals(other.getLoginCount()))
            && (this.getLastLoginTime() == null ? other.getLastLoginTime() == null : this.getLastLoginTime().equals(other.getLastLoginTime()))
            && (this.getLastLoginIp() == null ? other.getLastLoginIp() == null : this.getLastLoginIp().equals(other.getLastLoginIp()))
            && (this.getExpireTime() == null ? other.getExpireTime() == null : this.getExpireTime().equals(other.getExpireTime()))
            && (this.getUserType() == null ? other.getUserType() == null : this.getUserType().equals(other.getUserType()))
            && (this.getValidCode() == null ? other.getValidCode() == null : this.getValidCode().equals(other.getValidCode()))
            && (this.getCommentStatus() == null ? other.getCommentStatus() == null : this.getCommentStatus().equals(other.getCommentStatus()))
            && (this.getIpSource() == null ? other.getIpSource() == null : this.getIpSource().equals(other.getIpSource()))
            && (this.getBrowser() == null ? other.getBrowser() == null : this.getBrowser().equals(other.getBrowser()))
            && (this.getOprationSystem() == null ? other.getOprationSystem() == null : this.getOprationSystem().equals(other.getOprationSystem()))
            && (this.getStartEmailNotification() == null ? other.getStartEmailNotification() == null : this.getStartEmailNotification().equals(other.getStartEmailNotification()))
            && (this.getLoadingValid() == null ? other.getLoadingValid() == null : this.getLoadingValid().equals(other.getLoadingValid()))
            && (this.getDataOrigin() == null ? other.getDataOrigin() == null : this.getDataOrigin().equals(other.getDataOrigin()))
            && (this.getOriginUid() == null ? other.getOriginUid() == null : this.getOriginUid().equals(other.getOriginUid()))
            && (this.getOccupation() == null ? other.getOccupation() == null : this.getOccupation().equals(other.getOccupation()))
            && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getUserCode() == null) ? 0 : getUserCode().hashCode());
        result = prime * result + ((getUserName() == null) ? 0 : getUserName().hashCode());
        result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
        result = prime * result + ((getGender() == null) ? 0 : getGender().hashCode());
        result = prime * result + ((getAvatar() == null) ? 0 : getAvatar().hashCode());
        result = prime * result + ((getNickName() == null) ? 0 : getNickName().hashCode());
        result = prime * result + ((getBirthday() == null) ? 0 : getBirthday().hashCode());
        result = prime * result + ((getEmail() == null) ? 0 : getEmail().hashCode());
        result = prime * result + ((getPhone() == null) ? 0 : getPhone().hashCode());
        result = prime * result + ((getQqNumber() == null) ? 0 : getQqNumber().hashCode());
        result = prime * result + ((getWeChat() == null) ? 0 : getWeChat().hashCode());
        result = prime * result + ((getSummary() == null) ? 0 : getSummary().hashCode());
        result = prime * result + ((getSignature() == null) ? 0 : getSignature().hashCode());
        result = prime * result + ((getOrderNo() == null) ? 0 : getOrderNo().hashCode());
        result = prime * result + ((getLoginErrorCount() == null) ? 0 : getLoginErrorCount().hashCode());
        result = prime * result + ((getLoginCount() == null) ? 0 : getLoginCount().hashCode());
        result = prime * result + ((getLastLoginTime() == null) ? 0 : getLastLoginTime().hashCode());
        result = prime * result + ((getLastLoginIp() == null) ? 0 : getLastLoginIp().hashCode());
        result = prime * result + ((getExpireTime() == null) ? 0 : getExpireTime().hashCode());
        result = prime * result + ((getUserType() == null) ? 0 : getUserType().hashCode());
        result = prime * result + ((getValidCode() == null) ? 0 : getValidCode().hashCode());
        result = prime * result + ((getCommentStatus() == null) ? 0 : getCommentStatus().hashCode());
        result = prime * result + ((getIpSource() == null) ? 0 : getIpSource().hashCode());
        result = prime * result + ((getBrowser() == null) ? 0 : getBrowser().hashCode());
        result = prime * result + ((getOprationSystem() == null) ? 0 : getOprationSystem().hashCode());
        result = prime * result + ((getStartEmailNotification() == null) ? 0 : getStartEmailNotification().hashCode());
        result = prime * result + ((getLoadingValid() == null) ? 0 : getLoadingValid().hashCode());
        result = prime * result + ((getDataOrigin() == null) ? 0 : getDataOrigin().hashCode());
        result = prime * result + ((getOriginUid() == null) ? 0 : getOriginUid().hashCode());
        result = prime * result + ((getOccupation() == null) ? 0 : getOccupation().hashCode());
        result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
        return result;
    }

    @Override
    public int compareTo(BiUser newVal) {
        int newCount = 0;
        if (newVal.getUserStatsMap() != null) {
            if (newVal.getUserStatsMap().containsKey("blogCount")) {
                newCount += Integer.parseInt(newVal.getUserStatsMap().get("blogCount").toString());
            }
            if (newVal.getUserStatsMap().containsKey("followMeCount")) {
                newCount += Integer.parseInt(newVal.getUserStatsMap().get("followMeCount").toString());
            }
            if (newVal.getUserStatsMap().containsKey("likedCount")) {
                newCount += Integer.parseInt(newVal.getUserStatsMap().get("likedCount").toString());
            }
            if (newVal.getUserStatsMap().containsKey("dislikedCount")) {
                newCount -= Integer.parseInt(newVal.getUserStatsMap().get("dislikedCount").toString());
            }
            if (newVal.getUserStatsMap().containsKey("collectionedCount")) {
                newCount += Integer.parseInt(newVal.getUserStatsMap().get("collectionedCount").toString());
            }
        }
        int oldCount = 0;
        if (this.getUserStatsMap() != null) {
            if (this.getUserStatsMap().containsKey("blogCount")) {
                oldCount += Integer.parseInt(this.getUserStatsMap().get("blogCount").toString());
            }
            if (this.getUserStatsMap().containsKey("followMeCount")) {
                oldCount += Integer.parseInt(this.getUserStatsMap().get("followMeCount").toString());
            }
            if (this.getUserStatsMap().containsKey("likedCount")) {
                oldCount += Integer.parseInt(this.getUserStatsMap().get("likedCount").toString());
            }
            if (this.getUserStatsMap().containsKey("dislikedCount")) {
                oldCount -= Integer.parseInt(this.getUserStatsMap().get("dislikedCount").toString());
            }
            if (this.getUserStatsMap().containsKey("collectionedCount")) {
                oldCount += Integer.parseInt(this.getUserStatsMap().get("collectionedCount").toString());
            }
        }
        return Integer.compare(newCount, oldCount);
    }
}